/**
 * BillListPanel.java
 * @author pkendzo
 * Email: pkendzo@msn.com
 * 2010
 */
package lu.med.praxiswahl.wahlumed.client.rechnungen.op.view;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import lu.med.praxiswahl.wahlumed.client.rechnungen.op.model.BillItemModel;
import lu.med.praxiswahl.wahlumed.client.utilities.UniCode;
import lu.med.praxiswahl.wahlumed.client.wclient.PatientenSuchmaskeListener;


public class BillListPanel extends JPanel implements PatientenSuchmaskeListener, ListSelectionListener
{

    /**
     * 
     */
    private static final long serialVersionUID = -976827013449074287L;

    private DefaultListModel model;
    private JList list;
    private JScrollPane listPane;
    private BillItemsPanel billPan; 
   // private PatientenSuchmaske suchmaske;
    

    public BillListPanel()
    {
	super(new BorderLayout());
	this.setBorder(BorderFactory.createTitledBorder("Verf"
		+ UniCode.getue() + "gbare Rechnungen"));
	model = new DefaultListModel();

	this.billPan = new BillItemsPanel(this);

	list = new JList(model);
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.addListSelectionListener(this);
	listPane = new JScrollPane(list);
	this.add(listPane, BorderLayout.CENTER);
	this.add(billPan, BorderLayout.NORTH);
	this.setPreferredSize(new Dimension(150, 0));
    }

    /**
     * @param args
     */
    public static void main(String[] args)
    {

	JFrame frame = new JFrame("Test");
	// frame.setDefaultCloseOperation(System.exit(1));

	//frame.add(new BillListPanel());

	frame.setSize(400, 200);
	frame.setVisible(true);

    }

    @Override
    public void modelChanged(String matricule)
    {
	// Setzt das Attribut matricule im BillItemsPanel
	//this.billPan.setMatricule(matricule);
	BillFunctionPanel.customerMatricule = matricule;
	this.getModel().removeAllElements();
	
    }

    /**
     * @return the model
     */
    public DefaultListModel getModel()
    {
        return model;
    }

    /**
     * @param model the model to set
     */
    public void setModel(DefaultListModel model)
    {
        this.model = model;
    }

    /**
     * @return the billPan
     */
    public BillItemsPanel getBillPan()
    {
        return billPan;
    }

    /**
     * @param billPan the billPan to set
     */
    public void setBillPan(BillItemsPanel billPan)
    {
        this.billPan = billPan;
    }

    @Override
    public void valueChanged(ListSelectionEvent e)
    {
	if (list.getSelectedIndex() == -1)
	    return;
	BillItemModel.setBillNumber(((Long) list.getModel().getElementAt(list.getSelectedIndex())).longValue());
    }

    /**
     * @return the list
     */
    public JList getList()
    {
        return list;
    }

    /**
     * @param list the list to set
     */
    public void setList(JList list)
    {
        this.list = list;
    }
    
    
}
